define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'insurance/policy/index' + location.search,
                    add_url: 'insurance/policy/add',
                    edit_url: 'insurance/policy/edit',
                    del_url: 'insurance/policy/del',
                    multi_url: 'insurance/policy/multi',
                    import_url: 'insurance/policy/import',
                    table: 'insurance_policy',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'applyCode', title: __('ApplyCode'), operate: 'LIKE'},
                        {field: 'insuranceCode', title: __('InsuranceCode'), operate: 'LIKE'},
                        {field: 'insuredType', title: __('InsuredType'), searchList: { "0": __('InsuredType 0'), "11": __('InsuredType 11'), "12": __('InsuredType 12'), "21": __('InsuredType 21'), "22": __('InsuredType 22'), "23": __('InsuredType 23'), "24": __('InsuredType 24'), "61": __('InsuredType 61'), "62": __('InsuredType 62') , "80": __('InsuredType 80')}, formatter: Table.api.formatter.status },
                        {field: 'productType', title: __('ProductType'),searchList: { "1": __('ProductType 1'), "2": __('ProductType 2'), "6": __('ProductType 6'), "10": __('ProductType 10')}, formatter: Table.api.formatter.status},
                        {field: 'insuranceName', title: __('InsuranceName'), operate: 'LIKE'},
                        {field: 'insuredPerson', title: __('InsuredPerson'), operate: 'LIKE'},
                        {field: 'electronicPaperUrl', title: __('ElectronicPaperUrl'), operate: 'LIKE', formatter: Table.api.formatter.url},
                        {field: 'amount', title: __('Amount')},
                        {field: 'insuranceFee', title: __('InsuranceFee')},
                        {field: 'startTime', title: __('StartTime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'endTime', title: __('EndTime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'time', title: __('Time'),  operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'customerName', title: __('CustomerName'), operate: 'LIKE'},
                        {field: 'projectName', title: __('ProjectName'), operate: 'LIKE'},
                        {field: 'projectName', title: __('ProjectName'), operate: 'LIKE'},
                        {field: 'projectNO', title: __('ProjectNO'), operate: 'LIKE'},
                        {field: 'itemName', title: __('ItemName'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'itemNo', title: __('ItemNo'), operate: 'LIKE'},
                        {field: 'dictionary.fullName', title:'项目地址'},
                       
                        {field: 'result', title: __('Result'),searchList: { "0": __('Result 0'), "1": __('Result 1')}, formatter: Table.api.formatter.status},
                        {field: 'message', title: __('Message'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
